import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }

        long[] dp = new long[n + 1];
        long ret = Long.MIN_VALUE;
        for(int i = 1; i < n + 1; i++) {
            if(dp[i-1] >= 0) {
                dp[i] = dp[i-1] + a[i - 1];
            } else {
                dp[i] = a[i - 1];
            }
            ret = Math.max(ret, dp[i]);
        }
        System.out.println(ret);
    }
}